package com.cms.demo.config;

import com.cms.demo.interceptor.MyInterceptor01;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author wangning
 * @create 2021-04-27 9:06
 */
@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {
	/**
	 * 配置全局的跨域
	 * @param registry
	 */
	@Override
	public void addCorsMappings(CorsRegistry registry) {
		registry.addMapping("/**")
				.allowedHeaders("*")
				.allowedMethods("*")
				.maxAge(1800)
				.allowedOrigins("http://localhost:8090");
	}

	//配置拦截器

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(new MyInterceptor01())
				.addPathPatterns("/**")
				.excludePathPatterns("/add");
	}
}
